<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>事件绑定的简化写法</title>
</head>
<body>
    <div id="root"> </div>

    <script src="../js/react.development.js"></script>
    <script src="../js/react-dom.development.js"></script>
    <script src="../js/babel.min.js"></script>

    <script type="text/babel">
        class App extends React.Component{
            //state 设置
            state = {
                isNight: false
            }

            render(){
                //render 内部的 this 是指向『实例对象』的 
                //解构赋值  
                let {isNight} = this.state;
                return <div>
                        <h2 onMouseOver={this.mouseover}>至尊宝, 我是{isNight ? '青霞' : '紫霞'}</h2>
                        <button onClick={this.test}>点击切换白天与黑夜</button>
                    </div>        
            }

            //类内部的方法
            test = () => {
                let {isNight} = this.state;

                this.setState({
                    isNight: !isNight
                });
            }

            mouseover = () => {
                console.log('你把鼠标放到了我的身上');
            }
        }

        ReactDOM.render(<App />, document.querySelector("#root"));
    </script>
</body>
</html>